package hu.myai.model.graph;

import org.joone.log.ILogger;
import org.joone.log.LoggerFactory;

public class FibNode extends AbstractNode {

	private static final ILogger log = LoggerFactory.getLogger(FibNode.class);

	private float fibLevel;

	// Tolerance from the fibanocci is 5%
	private double fibTolerance = 0.10;

	// Tolerance from the fibanocci is 2%
	private double fibTolerance2 = fibTolerance * 2;

	public float getFibLevel() {
		return fibLevel;
	}

	public void setFibLevel(float fibLevel) {
		this.fibLevel = fibLevel;
	}

	/**
	 * @param level
	 *            sock pivot level for select a best suitable fibonacci level
	 * @return best suitable fibonacci level out of the possible next nodes
	 */
	public FibNode getNextNode(double level) {

		for (AbstractNode abstractNode : nextNodeList) {
			FibNode fibNode = (FibNode) abstractNode;
			if (Math.abs(level / fibNode.getFibLevel() - 1) < fibTolerance || level == 0.0
					&& fibNode.getFibLevel() == 0.0) {
				return fibNode;
			}
		}
		// for (AbstractNode abstractNode : nextNodeList) {
		// FibNode fibNode = (FibNode) abstractNode;
		//
		// if (Math.abs(level / fibNode.getFibLevel() - 1) < fibTolerance2) {
		// log.warn("Rough fibonacci level assosiated: " + level + " -> " +
		// fibNode.getFibLevel());
		// return fibNode;
		// }
		// }

		// log.debug("Warn - no fibonacci level is assosiated to level: " +
		// level);

		return null;
	}

}
